package zhou.teamwork14;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class UserDao {
	BaseDao bd=new BaseDao();
	Connection con=null;
	PreparedStatement ps=null;
	ResultSet rs=null;
	//关闭数据库
	public void close() throws SQLException{
		if(rs!=null){
			rs.close();
		}
		if(ps!=null){
			ps.close();
		}
		if(con!=null){
			con.close();
		}
	}
	//通过用户名查找数据库得用户信息
	public User selectUserbyName(String name) throws SQLException{
		con=bd.getCon();
		String sql="select *from user where username=?";
		ps=con.prepareStatement(sql);
		ps.setString(1, name);
		rs=ps.executeQuery();
		String username=null;
		String pwd=null;
		while(rs.next()){
			username=rs.getString("username");
			pwd=rs.getString("pwd");
		}
		User user=new User(username,pwd);
		return user;
	}
}
